<include file="Public/header"/>
<body class="body-bg">
<div class="park-header">
    <div class="park-header__title">我的收藏</div>
    <div class="park-header__left park-back">
        <i class="iconfont icon-fanhui"></i>
    </div>
</div>
<div class="container">
    <div class="park__goods" style="margin-top: 0.2rem;">
        <ul id="goods_list"></ul>
    </div>
</div>
</body>
<script src="__ROOT__/Public/Home/layer/layer.js"></script>
<script>
    function goods_detail(id,store_id){
        window.location = "{:U('Home/Index/detail',"",false)}/id/"+id+'/store_id/'+store_id;
    }
    var options = {
        type: 'get', // default 'get'
        dataType: 'html' // default 'json'
    };
    $(function () {
        var url = '/Home/User/ajaxcollect/';
        var params = {'page':1};
        PARK.dropLoad(PARK.dropAjax(options, url, params, function (data) {
            var data = JSON.parse(data);
            var html = '';
            for(var i=0;i<data.result.length;i++){
                html+='<li>';
                html+='    <div onclick="goods_detail('+data['result'][i]['id']+','+data['result'][i]['store_id']+');" class="park-goods__pic" style="background-image: url('+data['result'][i]['thumb']+')"></div>';
                html+='    <div onclick="goods_detail('+data['result'][i]['id']+','+data['result'][i]['store_id']+');" class="park-goods__info">';
                html+='        <p class="name">'+data['result'][i]['goods_name']+'</p>';
                html+='        <p class="desc">'+data['result'][i]['store_name']+'</p>';
                html+='        <p class="spec">'+data['result'][i]['spec_name']+'&nbsp;</p>';
                html += '        <p class="price-line">';
                html += '            <span class="price">￥<em>' + data['result'][i]['left_price'] + '</em>' + data['result'][i]['right_price'] + '</span>';
                html += '        </p>';
                html+='    </div>';

                html+='    <div class="park-goods__pos" onclick="sum_form('+data['result'][i]['id']+','+data['result'][i]['store_id']+','+data['result'][i]['spec_id']+');">';
                html+='        <i class="iconfont icon-cart goods-cart"></i>';
                html+='    </div>';
                html+='    <div class="park-goods__pos2" onclick="cancle_collect(this,'+data['result'][i]['cid']+');">';
                html+='        <i class="iconfont icon-shoucang goods-collect"></i>';
                html+='    </div>';
                html+='</li>';
            }
            if(html){
                $('#goods_list').append(html);
            }else {
                $('#goods_list').append('<div style="text-align:center;padding:50px;color:#ccc;">暂无收藏</div>');
            }
        }));
    });
    function sum_form(goods_id,store_id,spec_id){
        if(!spec_id){
            return false;
        }
        var goods_number = 1;
        $.post('/Home/Cart/add_cart/',{goods_id:goods_id,store_id:store_id,spec_id:spec_id,goods_number:goods_number},function(data){
            if(data.code==200){
                $('#cart_number').html(data.result);
            }
            layer.open({
                content:data.msg
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
        },'json');
    }
    function cancle_collect(obj,cid){
        $.post('/Home/User/cancle_collect/',{cid:cid},function(data){
            if(data.code==200){
                $(obj).parent().remove();
            }
            layer.open({
                content:data.msg
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
        },'json');
    }
</script>
</html>